<%@ Page Language="C#" MasterPageFile="~/Masterpages/Default.master" AutoEventWireup="true"
    Inherits="protected_ManageMenus" Title="Manage Menus" CodeBehind="ManageMenus.aspx.cs" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Src="../Usercontrols/Loading.ascx" TagName="Loading" TagPrefix="uc3" %>
<%@ Register Src="../Usercontrols/ChooseSite.ascx" TagName="ChooseSite" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <h1>
        Manage Site Menus</h1>
    <uc1:ChooseSite ID="ChooseSite1" runat="server" />
    <hr />
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
            Width="95%" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID,RowState,RowStamp,MenuType"
            DataSourceID="odsMenus" EmptyDataText="There are no menus in this site" OnRowCommand="GridView1_RowCommand"
            OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowUpdating="GridView1_RowUpdating"
            OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <EditRowStyle BackColor="#999999" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID" />
                <asp:TemplateField HeaderText="MenuType" SortExpression="MenuType">
                    <EditItemTemplate>
                        <%# ((Blazing.BusinessObjects.Cms.Menu)Container.DataItem).MenuType != null ? ((Blazing.BusinessObjects.Cms.Menu)Container.DataItem).MenuType.Name : "" %>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <%# ((Blazing.BusinessObjects.Cms.Menu)Container.DataItem).MenuType != null ? ((Blazing.BusinessObjects.Cms.Menu)Container.DataItem).MenuType.Name : "" %>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Prefix" HeaderText="Prefix" SortExpression="Prefix" />
                <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                <asp:CommandField SelectText="Items" ShowDeleteButton="True" ShowEditButton="True"
                    ShowSelectButton="True" />
            </Columns>
        </asp:GridView>
        <br />
        <asp:LinkButton ID="LinkButtonInsertMenu1" runat="server">Insert</asp:LinkButton>
        
        <asp:Panel ID="PanelAddMenu" runat="server" SkinID="PopupPanel1">
            <div class="PopupPanelInner" style="width: 300px;">
                <asp:Panel runat="server" ID="PanelAddMenuTitle" CssClass="PopupTitle">
                    Add Setting</asp:Panel>
                <br />
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataSourceID="odsMenus"
                    DefaultMode="Insert" OnItemCommand="DetailsView1_ItemCommand" OnItemInserting="DetailsView1_ItemInserting"
                    BorderWidth="0px">
                    <Fields>
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                            SortExpression="ID" />
                        <asp:TemplateField HeaderText="MenuType" SortExpression="MenuType">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MenuType") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:DropDownList ID="DropDownListMenuTypes" runat="server" DataSourceID="odsMenuTypes"
                                    DataTextField="Name" DataValueField="ID">
                                </asp:DropDownList>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("MenuType") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:BoundField DataField="Prefix" HeaderText="Prefix" SortExpression="Prefix" />
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
                        <asp:CommandField ShowInsertButton="True" />
                    </Fields>
                </asp:DetailsView>
            </div>
        </asp:Panel>
        <ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="LinkButtonInsertMenu1"
            PopupControlID="PanelAddMenu" PopupDragHandleControlID="PanelAddMenuTitle" SkinID="Popup1">
        </ajax:ModalPopupExtender>
        <asp:ObjectDataSource ID="odsMenus" runat="server" DataObjectTypeName="Blazing.BusinessObjects.Cms.Menu"
            DeleteMethod="DeleteMenu" InsertMethod="NewMenu" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetMenus" TypeName="Blazing.WebFacade.MenuController" UpdateMethod="UpdateMenu">
            <SelectParameters>
                <asp:SessionParameter DefaultValue="-1" Name="siteId" SessionField="siteId" Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <asp:ObjectDataSource ID="odsMenuTypes" runat="server" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetMenuTypes" TypeName="Blazing.WebFacade.MenuController"></asp:ObjectDataSource>
        <asp:ObjectDataSource ID="odsMenuItems" runat="server" DataObjectTypeName="Blazing.BusinessObjects.Cms.MenuItem"
            DeleteMethod="DeleteMenuItem" InsertMethod="NewMenuItem" OldValuesParameterFormatString="original_{0}"
            SelectMethod="GetMenuItems" TypeName="Blazing.WebFacade.MenuController" UpdateMethod="UpdateMenuItem"
            OnDeleted="odsMenuItems_Deleted" OnInserted="odsMenuItems_Inserted" OnUpdated="odsMenuItems_Updated">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="ID" PropertyName="SelectedValue"
                    Type="Int32" />
            </SelectParameters>
        </asp:ObjectDataSource>
        <br />
        <hr />
        <asp:Panel ID="PanelMenuItems" runat="server" Width="100%" Visible="False">
            <h1>
                Menu Items</h1>
            <fieldset>
                <legend>Menu Preview</legend>
                <asp:Menu ID="MenuEditor" runat="server" Orientation="Horizontal">
                </asp:Menu>
            </fieldset>

            <asp:GridView ID="GridViewMenuItems" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                CellPadding="4" DataKeyNames="ID,RowState,RowStamp,Parent" DataSourceID="odsMenuItems"
                EmptyDataText="There are no menu items in this menu" ForeColor="#333333" GridLines="None"
                Width="100%" OnRowUpdating="GridViewMenuItems_RowUpdating" OnDataBinding="GridViewMenuItems_DataBinding">
                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <Columns>
                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                        SortExpression="ID" />
                    <asp:BoundField DataField="SortOrder" HeaderText="Order" SortExpression="SortOrder" />
                    <asp:TemplateField HeaderText="Parent" SortExpression="Parent">
                        <EditItemTemplate>
                            <%# ((Blazing.BusinessObjects.Cms.MenuItem)Container.DataItem).Parent != null ? ((Blazing.BusinessObjects.Cms.MenuItem)Container.DataItem).Parent.Label : "" %>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <%# ((Blazing.BusinessObjects.Cms.MenuItem)Container.DataItem).Parent != null ? ((Blazing.BusinessObjects.Cms.MenuItem)Container.DataItem).Parent.Label : "" %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Label" HeaderText="Label" SortExpression="Label" />
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                </Columns>
                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                <EditRowStyle BackColor="#999999" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
            <asp:LinkButton ID="LinkButtonInsertMenuItem" runat="server" 
                Visible="false">Insert Menu Item</asp:LinkButton>
            <br />
            <div style="float: right">
                <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">Close</asp:LinkButton></div>
            <asp:LinkButton ID="LinkButtonInsertMenu" runat="server">Insert</asp:LinkButton>
            
            <asp:Panel ID="PanelAddMenuItem" runat="server" SkinID="PopupPanel1">
                <div class="PopupPanelInner" style="width: 300px;">
                    <asp:Panel runat="server" ID="PanelAddMenuItemTitle" CssClass="PopupTitle">
                        Add Menu Item</asp:Panel>
                    <br />
                    <asp:DetailsView ID="DetailsViewMenuItem" runat="server" AutoGenerateRows="False"
                        DataSourceID="odsMenuItems" DefaultMode="Insert" OnItemCommand="DetailsViewMenuItem_ItemCommand"
                        OnItemInserting="DetailsViewMenuItem_ItemInserting" BorderWidth="0px">
                        <Fields>
                            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                SortExpression="ID" />
                            <asp:BoundField DataField="Label" HeaderText="Label" SortExpression="Label" />
                            <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                            <asp:TemplateField HeaderText="Parent" SortExpression="Parent">
                                <EditItemTemplate>
                                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Parent") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <InsertItemTemplate>
                                    <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="odsMenuItems" DataTextField="Label"
                                        DataValueField="ID" AppendDataBoundItems="true">
                                        <asp:ListItem Selected="true" Value="">None</asp:ListItem>
                                    </asp:DropDownList>
                                </InsertItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("Parent") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:BoundField DataField="SortOrder" HeaderText="Order" SortExpression="SortOrder" />
                            <asp:CommandField ShowInsertButton="True" />
                        </Fields>
                    </asp:DetailsView>
                </div>
            </asp:Panel>
            <ajax:ModalPopupExtender ID="ModalPopupExtender2" runat="server" TargetControlID="LinkButtonInsertMenu"
                PopupControlID="PanelAddMenuItem" PopupDragHandleControlID="PanelAddMenuItemTitle"
                SkinID="Popup1">
            </ajax:ModalPopupExtender>
        </asp:Panel>
        <ajax:UpdateProgress runat="server" ID="update" DisplayAfter="50">
            <ProgressTemplate>
                <uc3:Loading ID="Loading1" runat="server" />
            </ProgressTemplate>
        </ajax:UpdateProgress>
        <asp:Menu ID="Menu1" runat="server">
        </asp:Menu>

</asp:Content>
